package ThreadDemo1;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 故我
 * Date: 2023-09-17
 * Time: 13:45
 */
public class ThreadDemo8 {
    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(()->{
           while(!Thread.currentThread().isInterrupted()){
               //获取这个线程，并判断是否停止
               System.out.println("Hello New Thread");
               try {
                   Thread.sleep(1000);
               } catch (InterruptedException e) {
                   e.printStackTrace();//这个异常会唤醒线程
//                   try {
//                       Thread.sleep(500);
//                   } catch (InterruptedException ex) {
//                       ex.printStackTrace();
//                   }
                    break;
               }
           }
        });
        t.start();
        Thread.sleep(3000);
        t.interrupt();
    }
}
